//
//  AnimationListViewController.m
//  MyFramework
//
//  Created by 余洋 on 2018/8/13.
//  Copyright © 2018年 余洋. All rights reserved.
//

#import "AnimationListViewController.h"
#import "MessageTableViewCell.h"
#import "TableViewCellAnimationViewController.h"
#import "CountdownViewController.h"

#import "MessageTableViewModel.h"

@interface AnimationListViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray<MessageTableViewModel *> *tableData;

@end

@implementation AnimationListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createData];
    [self createTabelView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UI配置
- (void)createTabelView {
    [self.tableView registerNib:[UINib nibWithNibName:@"MessageTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MessageTableViewCell"];
    self.tableView.estimatedRowHeight = 21.f;
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tableData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessageTableViewCell" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"MessageTableViewCell" owner:self options:nil].lastObject;
    }
    cell.model = self.tableData[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        TableViewCellAnimationViewController *cellAnimationVC = [[TableViewCellAnimationViewController alloc] init];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:cellAnimationVC animated:YES];
    } else if (indexPath.row == 1) {
        CountdownViewController *countdownVC = [[CountdownViewController alloc] init];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:countdownVC animated:YES];
    }
}

#pragma mark - 配置数据
- (void)createData {
    MessageTableViewModel *mode = [MessageTableViewModel new];
    mode.title = @"点击cell文字变大";
    [self.tableData addObject:mode];
    MessageTableViewModel *mode1 = [MessageTableViewModel new];
    mode1.title = @"计时器";
    [self.tableData addObject:mode1];
}

#pragma mark - 懒加载
- (NSMutableArray<MessageTableViewModel *>*)tableData {
    if (_tableData == nil) {
        _tableData = [NSMutableArray array];
    }
    return _tableData;
}

@end
